// pages/choosePlace/choosePlace.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //已选择城市
    location: '上海',
    //城市选择弹层显示
    locationShow: false,
    //品牌选择弹层显示
    bandShow: false,
    //自定义搜索弹层显示
    customShow: false,
    //自定义搜索文字
    customValue: '',
    //城市列表
    cityList: [],
    //省市列表
    bandList: [{
      id: 0,
      onthis: false,
      img: '../../images/band_logo_demo1.jpg'
    }, {
      id: 1,
      onthis: false,
      img: '../../images/band_logo_demo2.jpg'
    }, {
      id: 2,
      onthis: false,
      img: '../../images/band_logo_demo1.jpg'
    }, {
      id: 3,
      onthis: false,
      img: '../../images/band_logo_demo2.jpg'
    }, {
      id: 4,
      onthis: false,
      img: '../../images/band_logo_demo1.jpg'
    }, {
      id: 5,
      onthis: false,
      img: '../../images/band_logo_demo2.jpg'
    }, {
      id: 6,
      onthis: false,
      img: '../../images/band_logo_demo1.jpg'
    }, {
      id: 7,
      onthis: false,
      img: '../../images/band_logo_demo2.jpg'
    }, {
      id: 8,
      onthis: false,
      img: '../../images/band_logo_demo1.jpg'
    }, {
      id: 9,
      onthis: false,
      img: '../../images/band_logo_demo2.jpg'
    }, {
      id: 10,
      onthis: false,
      img: '../../images/band_logo_demo1.jpg'
    }, {
      id: 11,
      onthis: false,
      img: '../../images/band_logo_demo2.jpg'
    }],
    // 省份ID
    provinceListNum: 0,
    // 省份城市列表
    provinceList: [{
      id: 0,
      name: '上海',
      onthis: false,
      city: [{
        id: 0,
        name: '上海市',
        onthis: false
      }]
    }, {
      id: 1,
      name: '北京',
      onthis: false,
      city: [{
        id: 0,
        name: '北京市',
        onthis: false
      }]
    }, {
      id: 2,
      name: '天津',
      onthis: false,
      city: [{
        id: 0,
        name: '天津市',
        onthis: false
      }]
    }, {
      id: 3,
      name: '重庆',
      onthis: false,
      city: [{
        id: 0,
        name: '重庆市',
        onthis: false
      }]
    }, {
      id: 4,
      name: '江苏',
      onthis: false,
      city: [{
        id: 0,
        name: '南京',
        onthis: false
      }, {
        id: 1,
        name: '无锡',
        onthis: false
      }, {
        id: 2,
        name: '徐州',
        onthis: false
      }, {
        id: 3,
        name: '常州',
        onthis: false
      }, {
        id: 4,
        name: '苏州',
        onthis: false
      }, {
        id: 5,
        name: '南通',
        onthis: false
      }, {
        id: 6,
        name: '连云港',
        onthis: false
      }, {
        id: 7,
        name: '淮安',
        onthis: false
      }, {
        id: 8,
        name: '盐城',
        onthis: false
      }, {
        id: 9,
        name: '扬州',
        onthis: false
      }]
    }, {
      id: 5,
      name: '浙江',
      onthis: false,
      city: [{
        id: 0,
        name: '南京',
        onthis: false
      }, {
        id: 1,
        name: '无锡',
        onthis: false
      }, {
        id: 2,
        name: '徐州',
        onthis: false
      }, {
        id: 3,
        name: '常州',
        onthis: false
      }, {
        id: 4,
        name: '苏州',
        onthis: false
      }, {
        id: 5,
        name: '南通',
        onthis: false
      }, {
        id: 6,
        name: '连云港',
        onthis: false
      }, {
        id: 7,
        name: '淮安',
        onthis: false
      }, {
        id: 8,
        name: '盐城',
        onthis: false
      }, {
        id: 9,
        name: '扬州',
        onthis: false
      }]
    }, {
      id: 6,
      name: '安徽',
      onthis: false,
      city: [{
        id: 0,
        name: '南京',
        onthis: false
      }, {
        id: 1,
        name: '无锡',
        onthis: false
      }, {
        id: 2,
        name: '徐州',
        onthis: false
      }, {
        id: 3,
        name: '常州',
        onthis: false
      }, {
        id: 4,
        name: '苏州',
        onthis: false
      }, {
        id: 5,
        name: '南通',
        onthis: false
      }, {
        id: 6,
        name: '连云港',
        onthis: false
      }, {
        id: 7,
        name: '淮安',
        onthis: false
      }, {
        id: 8,
        name: '盐城',
        onthis: false
      }, {
        id: 9,
        name: '扬州',
        onthis: false
      }]
    }, {
      id: 7,
      name: '广东',
      onthis: false,
      city: [{
        id: 0,
        name: '南京',
        onthis: false
      }, {
        id: 1,
        name: '无锡',
        onthis: false
      }, {
        id: 2,
        name: '徐州',
        onthis: false
      }, {
        id: 3,
        name: '常州',
        onthis: false
      }, {
        id: 4,
        name: '苏州',
        onthis: false
      }, {
        id: 5,
        name: '南通',
        onthis: false
      }, {
        id: 6,
        name: '连云港',
        onthis: false
      }, {
        id: 7,
        name: '淮安',
        onthis: false
      }, {
        id: 8,
        name: '盐城',
        onthis: false
      }, {
        id: 9,
        name: '扬州',
        onthis: false
      }]
    }, {
      id: 8,
      name: '四川',
      onthis: false,
      city: [{
        id: 0,
        name: '南京',
        onthis: false
      }, {
        id: 1,
        name: '无锡',
        onthis: false
      }, {
        id: 2,
        name: '徐州',
        onthis: false
      }, {
        id: 3,
        name: '常州',
        onthis: false
      }, {
        id: 4,
        name: '苏州',
        onthis: false
      }, {
        id: 5,
        name: '南通',
        onthis: false
      }, {
        id: 6,
        name: '连云港',
        onthis: false
      }, {
        id: 7,
        name: '淮安',
        onthis: false
      }, {
        id: 8,
        name: '盐城',
        onthis: false
      }, {
        id: 9,
        name: '扬州',
        onthis: false
      }]
    }, {
      id: 9,
      name: '福建',
      onthis: false,
      city: [{
        id: 0,
        name: '南京',
        onthis: false
      }, {
        id: 1,
        name: '无锡',
        onthis: false
      }, {
        id: 2,
        name: '徐州',
        onthis: false
      }, {
        id: 3,
        name: '常州',
        onthis: false
      }, {
        id: 4,
        name: '苏州',
        onthis: false
      }, {
        id: 5,
        name: '南通',
        onthis: false
      }, {
        id: 6,
        name: '连云港',
        onthis: false
      }, {
        id: 7,
        name: '淮安',
        onthis: false
      }, {
        id: 8,
        name: '盐城',
        onthis: false
      }, {
        id: 9,
        name: '扬州',
        onthis: false
      }]
    }],
    //机构列表
    placeList: [{
      id: 0,
      onthis: false,
      canChoose: true,
      img: '../../images/place_demo.jpg',
      name: '上海瑞慈徐汇体检中心',
      last: true,
      icon: '去年体验',
      iconImg: '../../images/last_year_icon.png',
      dist: 1.1,
      add: '上海市徐汇区斜土路2899号光启文化广场B幢7楼'
    }, {
      id: 1,
      onthis: false,
      canChoose: true,
      img: '../../images/place_demo.jpg',
      name: '上海美年徐汇体检中心',
      icon: '',
      dist: 2.5,
      add: '上海市徐汇区漕溪北路2223号'
    }, {
      id: 2,
      onthis: false,
      canChoose: false,
      img: '../../images/place_demo.jpg',
      name: '上海瑞慈漕河泾体检中心',
      icon: '装修中',
      iconImg: '../../images/trimming_icon.png',
      dist: 4.1,
      add: '上海市徐汇区宜山路1388号民润商务楼1号楼3楼'
    }, {
      id: 3,
      onthis: false,
      canChoose: true,
      img: '../../images/place_demo.jpg',
      name: '上海美年漕河泾体检中心',
      icon: '',
      dist: 4.5,
      add: '上海市闵行区漕宝路2345号'
    }, {
      id: 4,
      onthis: false,
      canChoose: true,
      img: '../../images/place_demo.jpg',
      name: '上海瑞慈徐汇体检中心',
      icon: '',
      dist: 1.1,
      add: '上海市徐汇区斜土路2899号光启文化广场B幢7楼'
    }, {
      id: 5,
      onthis: false,
      canChoose: true,
      img: '../../images/place_demo.jpg',
      name: '上海美年徐汇体检中心',
      icon: '',
      dist: 2.5,
      add: '上海市徐汇区漕溪北路2223号'
    }, {
      id: 6,
      onthis: false,
      canChoose: false,
      img: '../../images/place_demo.jpg',
      name: '上海瑞慈漕河泾体检中心',
      icon: '装修中',
      iconImg: '../../images/trimming_icon.png',
      dist: 4.1,
      add: '上海市徐汇区宜山路1388号民润商务楼1号楼3楼'
    }, {
      id: 7,
      onthis: false,
      canChoose: true,
      img: '../../images/place_demo.jpg',
      name: '上海美年漕河泾体检中心',
      icon: '',
      dist: 4.5,
      add: '上海市闵行区漕宝路2345号'
    }],
  },
  onLoad: function (options) { },
  //选择机构
  choosePlace: function (e) {
    let id = e.currentTarget.id,
      list = this.data.placeList;
    for (let i = 0; i < list.length; i++) {
      if (id == list[i].id) {
        if (!list[i].canChoose) return;
        list[i].onthis = true;
      } else {
        list[i].onthis = false;
      }
    }
    this.setData({
      placeList: list
    })
  },
  //省份点击事件
  provinceTap: function (e) {
    let id = e.currentTarget.id,
      list = this.data.provinceList,
      cityList = this.data.cityList;
    for (let i = 0; i < list.length; i++) {
      if (id == list[i].id) {
        list[i].onthis = true
        cityList = list[i].city
      } else {
        list[i].onthis = false
      }
    }
    this.setData({
      provinceList: list,
      cityList,
      provinceListNum: id
    })
  },
  //城市点击事件
  cityTap: function (e) {
    let id = e.currentTarget.id,
      num = this.data.provinceListNum,
      provinceList = this.data.provinceList,
      list = this.data.cityList,
      name = '';
    for (let i = 0; i < list.length; i++) {
      if (id == list[i].id) {
        name = list[i].name;
        list[i].onthis = true;
      } else {
        list[i].onthis = false;
      }
    }
    // for (let j = 0; j < provinceList.length; j++) {
    //   if (num == provinceList[j].id) {
    //     provinceList[j].city = list;
    //   } else {
    //     for (let k = 0; k < provinceList[j].city[k].length; k++) {
    //       provinceList[j].city[k].onthis = false;
    //     }
    //   }
    // }
    this.setData({
      location: name,
      locationShow: false,
      cityList: list,
      //provinceList
    })
  },
  //品牌选择点击事件
  bandChooseTap: function (e) {
    let id = e.currentTarget.id,
      list = this.data.bandList;
    for (let i = 0; i < list.length; i++) {
      if (id == list[i].id) {
        if (list[i].onthis) {
          list[i].onthis = false
        } else {
          list[i].onthis = true
        }
      }
    }
    this.setData({
      bandList: list,
    })
  },
  //品牌选择重置点击事件
  clearBandChoose: function (e) {
    let id = e.currentTarget.id,
      list = this.data.bandList;
    for (let i = 0; i < list.length; i++) {
      list[i].onthis = false
    }
    this.setData({
      bandList: list,
    })
  },
  //品牌选择确认点击事件
  confirmBandChoose: function (e) {
    this.setData({
      bandShow: false,
    })
  },
  //自定义搜索重置输入点击事件
  clearCustomInput: function (e) {
    this.setData({
      customValue: '',
    })
  },
  //自定义搜索确认搜索点击事件
  confirmCustomInput: function (e) {
    wx.navigateTo({
      url: '../search/search',
    })
    this.setData({
      customShow: false,
    })
  },
  //自定义搜索关闭点击事件
  closeCustom: function (e) {
    this.setData({
      customShow: false,
    })
  },
  //位置选择按钮点击事件
  locationShow: function (e) {
    this.setData({
      locationShow: true,
    })
  },
  //位置选择关闭按钮点击事件
  locationClose: function (e) {
    this.setData({
      locationShow: false,
    })
  },
  //品牌选择按钮点击事件
  bandShow: function (e) {
    this.setData({
      bandShow: true,
    })
  },
  //自定义搜索按钮点击事件
  customShow: function (e) {
    this.setData({
      customShow: true,
    })
  },
  closePop: function (e) {
    this.setData({
      bandShow: false,
      customShow: false,
    })
  }
})